home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / atileg1a / frmtilet.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-29  |  14.2 KB  |  471 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTileTest 
  3.    Caption         =   "Map Creation"
  4.    ClientHeight    =   9420
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   10440
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   628
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   696
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.CommandButton vmdAbout 
  14.       Caption         =   "About"
  15.       Height          =   375
  16.       Left            =   150
  17.       TabIndex        =   20
  18.       Top             =   90
  19.       Width           =   1155
  20.    End
  21.    Begin VB.PictureBox imgZoom 
  22.       Height          =   915
  23.       Left            =   180
  24.       ScaleHeight     =   855
  25.       ScaleWidth      =   945
  26.       TabIndex        =   19
  27.       Top             =   540
  28.       Width           =   1005
  29.    End
  30.    Begin VB.PictureBox Outer 
  31.       Height          =   6675
  32.       Left            =   30
  33.       ScaleHeight     =   441
  34.       ScaleMode       =   3  'Pixel
  35.       ScaleWidth      =   345
  36.       TabIndex        =   15
  37.       Top             =   1500
  38.       Width           =   5235
  39.       Begin VB.HScrollBar HScroll1 
  40.          Height          =   255
  41.          LargeChange     =   5
  42.          Left            =   0
  43.          Max             =   200
  44.          TabIndex        =   18
  45.          Top             =   7830
  46.          Width           =   7905
  47.       End
  48.       Begin VB.VScrollBar VScroll1 
  49.          Height          =   8085
  50.          LargeChange     =   5
  51.          Left            =   7920
  52.          Max             =   200
  53.          TabIndex        =   17
  54.          Top             =   0
  55.          Width           =   285
  56.       End
  57.       Begin VB.PictureBox Inner 
  58.          BackColor       =   &H00FF0000&
  59.          FillColor       =   &H00FF0000&
  60.          Height          =   79650
  61.          Left            =   0
  62.          ScaleHeight     =   5306
  63.          ScaleMode       =   3  'Pixel
  64.          ScaleWidth      =   4746
  65.          TabIndex        =   16
  66.          Top             =   0
  67.          Width           =   71250
  68.          Begin VB.Image imgSml 
  69.             Height          =   15
  70.             Left            =   4200
  71.             Top             =   5550
  72.             Width           =   15
  73.          End
  74.          Begin VB.Image castle 
  75.             Height          =   720
  76.             Index           =   0
  77.             Left            =   690
  78.             Picture         =   "frmTileTest.frx":0000
  79.             Stretch         =   -1  'True
  80.             Top             =   720
  81.             Visible         =   0   'False
  82.             Width           =   720
  83.          End
  84.          Begin VB.Image imgTile 
  85.             Appearance      =   0  'Flat
  86.             BorderStyle     =   1  'Fixed Single
  87.             Height          =   1440
  88.             Index           =   0
  89.             Left            =   0
  90.             Picture         =   "frmTileTest.frx":3042
  91.             Stretch         =   -1  'True
  92.             Tag             =   "0"
  93.             Top             =   0
  94.             Width           =   1440
  95.          End
  96.       End
  97.    End
  98.    Begin VB.Frame Frame2 
  99.       Caption         =   "File"
  100.       Height          =   1185
  101.       Left            =   3510
  102.       TabIndex        =   9
  103.       Top             =   60
  104.       Width           =   1995
  105.       Begin VB.CommandButton Command1 
  106.          Caption         =   "Save"
  107.          Height          =   255
  108.          Left            =   390
  109.          TabIndex        =   12
  110.          Top             =   840
  111.          Width           =   1125
  112.       End
  113.       Begin VB.CommandButton Command2 
  114.          Caption         =   "Load"
  115.          Height          =   285
  116.          Left            =   390
  117.          TabIndex        =   11
  118.          Top             =   540
  119.          Width           =   1125
  120.       End
  121.       Begin VB.TextBox txtFile 
  122.          Height          =   285
  123.          Left            =   930
  124.          TabIndex        =   10
  125.          Text            =   "out"
  126.          Top             =   210
  127.          Width           =   975
  128.       End
  129.       Begin VB.Label Label4 
  130.          AutoSize        =   -1  'True
  131.          Caption         =   "Filename :"
  132.          Height          =   195
  133.          Left            =   180
  134.          TabIndex        =   13
  135.          Top             =   240
  136.          Width           =   720
  137.       End
  138.    End
  139.    Begin VB.Frame Frame1 
  140.       Caption         =   "Misc :"
  141.       Height          =   975
  142.       Left            =   5700
  143.       TabIndex        =   5
  144.       Top             =   180
  145.       Width           =   1875
  146.       Begin VB.TextBox Text1 
  147.          Height          =   285
  148.          Left            =   1170
  149.          TabIndex        =   7
  150.          Text            =   "4"
  151.          Top             =   240
  152.          Width           =   555
  153.       End
  154.       Begin VB.CheckBox chkGrid 
  155.          Caption         =   "Grid On"
  156.          Height          =   285
  157.          Left            =   270
  158.          TabIndex        =   6
  159.          Top             =   600
  160.          Value           =   1  'Checked
  161.          Width           =   945
  162.       End
  163.       Begin VB.Label Label2 
  164.          AutoSize        =   -1  'True
  165.          Caption         =   "Zoom Factor:"
  166.          Height          =   195
  167.          Left            =   180
  168.          TabIndex        =   8
  169.          Top             =   270
  170.          Width           =   945
  171.       End
  172.    End
  173.    Begin VB.Frame fmGridSize 
  174.       Caption         =   "Grid Size :"
  175.       Height          =   1365
  176.       Left            =   1380
  177.       TabIndex        =   0
  178.       Top             =   30
  179.       Width           =   1965
  180.       Begin VB.CommandButton cmdClear 
  181.          Caption         =   "Clear"
  182.          Height          =   315
  183.          Left            =   300
  184.          TabIndex        =   14
  185.          Top             =   960
  186.          Width           =   1485
  187.       End
  188.       Begin VB.CommandButton cmdResize 
  189.          Caption         =   "Change Size"
  190.          Height          =   285
  191.          Left            =   300
  192.          TabIndex        =   4
  193.          Top             =   630
  194.          Width           =   1455
  195.       End
  196.       Begin VB.TextBox txtCol 
  197.          Height          =   375
  198.          Left            =   1200
  199.          TabIndex        =   2
  200.          Text            =   "20"
  201.          Top             =   240
  202.          Width           =   555
  203.       End
  204.       Begin VB.TextBox txtRow 
  205.          Height          =   375
  206.          Left            =   240
  207.          TabIndex        =   1
  208.          Text            =   "20"
  209.          Top             =   240
  210.          Width           =   555
  211.       End
  212.       Begin VB.Label Label3 
  213.          AutoSize        =   -1  'True
  214.          Caption         =   "by"
  215.          Height          =   195
  216.          Left            =   900
  217.          TabIndex        =   3
  218.          Top             =   330
  219.          Width           =   165
  220.       End
  221.    End
  222.    Begin VB.Image imgArrow 
  223.       Height          =   480
  224.       Left            =   8700
  225.       Picture         =   "frmTileTest.frx":3884
  226.       Top             =   240
  227.       Visible         =   0   'False
  228.       Width           =   480
  229.    End
  230. Attribute VB_Name = "frmTileTest"
  231. Attribute VB_GlobalNameSpace = False
  232. Attribute VB_Creatable = False
  233. Attribute VB_PredeclaredId = True
  234. Attribute VB_Exposed = False
  235. ' The main form,
  236. ' Click on a texture in the texture's form and then on a cell in this form to
  237. ' place it.
  238. Option Explicit
  239. Private CONSTPath As String
  240. Const SEAPic = 53
  241. Private ActiveTile As Integer
  242. Private ZoomLevel As Double
  243. Private Map As Map
  244. 'Private Tile(400) As Tile
  245. Private ImageLoaded As Boolean
  246. Private Sub castle_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, y As Single)
  247.   castle(Index).Drag vbBeginDrag
  248. End Sub
  249. Private Sub chkGrid_Click()
  250. Dim i As Integer
  251.   If chkGrid.Value = vbChecked Then
  252.     For i = 0 To Map.Rows * Map.Cols - 1
  253.       imgTile(i).BorderStyle = 1
  254.     Next
  255.   Else
  256.     For i = 0 To Map.Rows * Map.Cols - 1
  257.       imgTile(i).BorderStyle = 0
  258.     Next
  259.   End If
  260. End Sub
  261. Private Sub cmdClear_Click()
  262. Dim i As Integer
  263.   For i = 0 To Map.Rows * Map.Cols - 1
  264.     imgTile(i).Picture = frmTextures.picTile(SEAPic).Picture
  265.     Map(i).Image = SEAPic
  266.   Next
  267. End Sub
  268. Private Sub cmdResize_Click()
  269. Dim i As Integer
  270.   'Set Map = New Map
  271.   Call Map.CreateArray(CInt(txtRow), CInt(txtCol))
  272.   Call Map.ClearArray
  273.   For i = 0 To imgTile.UBound - 1
  274.     imgTile(i).Visible = False
  275.   Next
  276.   Call CreateImageArray
  277. End Sub
  278. Private Sub Command1_Click()
  279.   Call WriteToFile
  280. End Sub
  281. Private Sub Command2_Click()
  282. Dim i As Integer
  283.   Call LoadDataFile(txtFile.Text)
  284.   For i = 0 To imgTile.UBound - 1
  285.     imgTile(i).Visible = False
  286.   Next
  287.   Call CreateImageArray
  288.   Draw
  289. End Sub
  290. Private Sub Form_Load()
  291. Dim i As Integer
  292.   ZoomLevel = 2
  293.   CONSTPath = App.Path & "\data\"
  294.   Set Map = New Map
  295.   Call Map.CreateArray(20, 20)
  296.   Call Map.ClearArray
  297.   Call CreateImageArray
  298.   imgZoom.Picture = frmTextures.picTile(SEAPic).Picture
  299.   imgZoom.Tag = SEAPic
  300.   frmTextures.Show
  301.   ImageLoaded = False
  302.   frmTileTest.Show
  303.   DoEvents
  304.   ImageLoaded = True
  305. End Sub
  306. Private Sub CreateImageArray()
  307. Dim i As Integer
  308.   imgTile(0).Width = (16 * ZoomLevel)
  309.   imgTile(0).Height = (16 * ZoomLevel)
  310.   imgTile(0).Stretch = True
  311.   imgTile(0).Visible = True
  312.   For i = 1 To Map.Cols * Map.Rows - 1
  313. On Error Resume Next
  314.     Load imgTile(i)
  315. On Error GoTo 0
  316.    ' Set Map.Item(i) = New Tile
  317.     imgTile(i).Visible = False
  318.     imgTile(i).Left = imgTile(i - 1).Left + (16 * ZoomLevel)
  319.     imgTile(i).Top = imgTile(i - 1).Top
  320.     imgTile(i).ToolTipText = i
  321.     If CDbl((i / Map.Cols) - CInt(i / Map.Cols)) = 0 Then
  322.       imgTile(i).Top = imgTile(i - 1).Top + (16 * ZoomLevel)
  323.       imgTile(i).Left = imgTile(0).Left
  324.     End If
  325.     imgTile(i).Width = (16 * ZoomLevel)
  326.     imgTile(i).Height = (16 * ZoomLevel)
  327.     imgTile(i).Stretch = True
  328.     imgTile(i).Visible = True
  329.   Next
  330. End Sub
  331. Private Sub LoadDataFile(fName As String)
  332. Dim ff As Long
  333. Dim int1 As Integer
  334. Dim int2 As Integer
  335. Dim i As Integer
  336. Dim str As String
  337.   ff = FreeFile
  338.   Open CONSTPath & fName & ".map" For Input As ff
  339.     Input #ff, str
  340.     int1 = CInt(str)
  341.     Input #ff, str
  342.     int2 = CInt(str)
  343.     Set Map = New Map
  344.     Call Map.CreateArray(int1, int2)
  345.     For i = 0 To Map.Cols * Map.Rows - 1
  346.       'Debug.Print Input(1, #ff)
  347.       'Input #ff, interg
  348.       If Not EOF(ff) Then
  349.         Input #ff, str
  350.         int1 = CInt(str)
  351.         
  352.         Call Map.AddItem(int1, int2)
  353.       Else
  354.         Debug.Print i
  355.       End If
  356.     Next
  357.   Close #1
  358. End Sub
  359. Private Sub Form_Resize()
  360.   Outer.Width = Me.ScaleWidth - Outer.Left
  361.   Outer.Height = Me.ScaleHeight - Outer.Top
  362.   VScroll1.Left = Outer.ScaleWidth - VScroll1.Width
  363.   VScroll1.Height = Outer.ScaleHeight
  364.   HScroll1.Top = Outer.ScaleHeight - HScroll1.Height
  365.   HScroll1.Left = 0
  366.   HScroll1.Width = Outer.ScaleWidth - VScroll1.Width
  367. End Sub
  368. Private Sub Form_Unload(Cancel As Integer)
  369.   Unload frmTextures
  370. End Sub
  371. Private Sub HScroll1_Change()
  372.   'HScroll1.Value
  373.   Inner.Left = 0 - (HScroll1.Value * 16 * ZoomLevel)
  374. End Sub
  375. Private Sub WriteToFile()
  376. Dim ff As Long
  377. Dim i As Integer
  378.   ff = FreeFile
  379.   Open CONSTPath & txtFile.Text & ".map" For Output As ff
  380.     Write #ff, Map.Rows
  381.     Write #ff, Map.Cols
  382.     For i = 0 To Map.Rows * Map.Cols - 1
  383.       Write #ff, Map(i).Image
  384. '      Write #ff, Map(i).Image(1)
  385.     Next
  386.   Close #1
  387. End Sub
  388. Private Sub RedrawScreen()
  389. Dim i As Integer
  390. On Error GoTo 0
  391.   imgTile(0).Width = (16 * ZoomLevel)
  392.   imgTile(0).Height = (16 * ZoomLevel)
  393.   imgTile(0).Stretch = True
  394.   For i = 1 To Map.Rows * Map.Cols - 1
  395. '    Load imgTile(i)
  396.     imgTile(i).Visible = False
  397.     imgTile(i).Left = imgTile(i - 1).Left + (16 * ZoomLevel)
  398.     imgTile(i).Top = imgTile(i - 1).Top
  399.     If CDbl((i / Map.Cols) - CInt(i / Map.Cols)) = 0 Then
  400.       imgTile(i).Top = imgTile(i - 1).Top + (16 * ZoomLevel)
  401.       imgTile(i).Left = imgTile(0).Left
  402.     End If
  403.     imgTile(i).Width = (16 * ZoomLevel)
  404.     imgTile(i).Height = (16 * ZoomLevel)
  405.     imgTile(i).Stretch = True
  406.     'imgTile(i).Picture = imgAvailTiles(imgTile(i).Tag).Picture
  407.     imgTile(i).Visible = True
  408.   Next
  409.   For i = 0 To 1
  410.     castle(i).Width = (16 * ZoomLevel) / 2
  411.     castle(i).Height = (16 * ZoomLevel) / 2
  412.   Next
  413. End Sub
  414. Private Sub imgTile_DragDrop(Index As Integer, Source As Control, X As Single, y As Single)
  415.   If (Me.ScaleX(X, vbTwips, vbPixels)) > (imgTile(Index).Width / 2) Then
  416.     Source.Left = imgTile(Index).Width / 2
  417.   Else
  418.     Source.Left = 0
  419.   End If
  420.   Source.Left = Source.Left + imgTile(Index).Left
  421.   If (ScaleY(y, vbTwips, vbPixels)) > (imgTile(Index).Height / 2) Then
  422.     Source.Top = imgTile(Index).Height / 2
  423.   Else
  424.     Source.Top = 0
  425.   End If
  426.   Source.Top = Source.Top + imgTile(Index).Top
  427. End Sub
  428. Private Sub imgTile_DragOver(Index As Integer, Source As Control, X As Single, y As Single, State As Integer)
  429.   If Source = imgSml Then
  430.     imgTile(Index).Picture = imgZoom.Picture
  431.    Map(Index).Image = imgZoom.Tag
  432.   End If
  433. End Sub
  434. Private Sub imgTile_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, y As Single)
  435.   ActiveTile = Index
  436.   If imgZoom.Tag <> -1 Then
  437.     If Button = vbLeftButton Then
  438.      Map(Index).Image = imgZoom.Tag
  439.      imgTile(Index).Picture = imgZoom.Picture
  440.     Else
  441.       Debug.Print X / Screen.TwipsPerPixelX & " : " & y / Screen.TwipsPerPixelY
  442.     End If
  443.   End If
  444. End Sub
  445. Private Sub Text1_LostFocus()
  446. On Error Resume Next
  447.   ZoomLevel = CDbl(Text1.Text)
  448.   If ZoomLevel <= 0 Then ZoomLevel = 1
  449.   Call RedrawScreen
  450. End Sub
  451. Private Sub vmdAbout_Click()
  452.   frmAbout.Show 1, Me
  453. End Sub
  454. Private Sub VScroll1_Change()
  455.   Inner.Top = 0 - (VScroll1.Value * 16 * ZoomLevel)
  456. End Sub
  457. Private Sub Draw()
  458. Dim i As Integer
  459. Dim j As Integer
  460. Dim t As Double
  461.   t = Timer
  462.   If ImageLoaded Then
  463.     For i = 0 To Map.Rows * Map.Cols - 1
  464.       imgTile(i).Picture = frmTextures.picTile(Map(i).Image).Picture
  465.     Next
  466.     Debug.Print "Draw complete"
  467.   End If
  468.   t = Timer - t
  469.   Debug.Print "Time to redraw :" & t
  470. End Sub
  471.